using Android.App;
using Android.Content;
using Android.OS;
using Android.Widget;
using Android.Media;
using Android.Graphics;
using System;
using Java.IO;
using System.IO;

namespace EightBeats
{
    [Activity(Label = "Converting...")]
    public class ConvertActivity : Activity
    {
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Convert);

            //Set File Name
            TextView txtFileName = FindViewById<TextView>(Resource.Id.txtFileName);

            try
            {
                Android.Net.Uri originalAudioUri = Android.Net.Uri.Parse(Intent.GetStringExtra("FileToConvert"));
                string originalAudioPath = Util.GetAudioRealPathFromURI(this, originalAudioUri);
                string base64Str = GetBase64Str(originalAudioPath);
            }
            catch(Exception ex)
            {
                Toast.MakeText(this, "An error just occurred: " + ex.Message, ToastLength.Short).Show();
            }


            //UploadAudio(filePath);
        }

        protected string GetBase64Str(string path)
        {
            using (FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read))
            {
                byte[] audioData = new byte[fs.Length];
                fs.Read(audioData, 0, System.Convert.ToInt32(fs.Length));
                return Convert.ToBase64String(audioData);
            }
        }

        protected Guid UploadAudio(string path)
        {
            return Guid.NewGuid();
        }

        protected bool DownloadAudio(Guid id)
        {
            return true;
        }

        protected void SetStatus(string status)
        {
            TextView txtStatus = FindViewById<TextView>(Resource.Id.txtStatus);
            txtStatus.SetTypeface(null, TypefaceStyle.Italic);
            txtStatus.Text = status;
        }
    }
}